//
//  ServerController.h
//  Server
//
//  Created by Kevin Schewior on 12/7/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ServerMessaging.h"
#import "ServerThreadController.h"
#import "Team.h"
#import "Checkpoint.h"
#import "Operator.h"
#import "Hunter.h"
#import "Runner.h"
#import "NetworkMessageCreator.h"
#import "ServerHelper.h"

@interface ServerController : NSWindowController<ServerMessaging> {
    ServerThreadController *stc;
	
	//mutable dictionaries storing the current game state
	NSMutableDictionary* teams;
    NSMutableDictionary* players;
	NSMutableDictionary* checkpoints;
    NSMutableDictionary* catchingTimers;
}

-(IBAction) startServer: (id)sender;

//Keyframes method called every x seconds
-(void) sendKeyframes:(NSTimer*) timer;

//Methods reacting to messages
-(void) loginWithClientID:(NSString*) clientID andPlayerName:(NSString*) playerName andTeamID:(NSString*) teamID andRole:(int) role andMsgID:(int) msgID;
-(void) logoutWithClientID:(NSString*) clientID andMsgID:(int) msgID;
-(void) updateLocationWithClientID:(NSString*) clientID andLong:(double) x andLat:(double) y andAccuracy:(double) accuracy;
-(void) assignCheckpoint:(NSString*)checkpointID toRunner:(NSString*)runnerID assign:(bool)assign byOperator:(NSString*)operatorID;
-(void) assignRunner:(NSString*)runnerID toHunter:(NSString*)hunterID assign:(bool)assign byOperator:(NSString*)operatorID;
-(void) sendCatchMessageWithAllow:(bool) allow toPlayer:(LocatedPlayer*)player;
-(void) sendBringHomeMessageWithAllow:(bool) allow toPlayer:(LocatedPlayer*)player;
-(bool) catchDistanceBetweenPlayerA:(NSString*)playerAID andPlayerB:(NSString*)playerBID;
-(bool) catchDistanceBetweenPlayer:(NSString*)playerID andCheckpoint:(NSString*)checkpointID;
-(bool) bringHomeDistanceForPlayer:(NSString*)playerID;
-(void) startCatchWithPlayer:(NSString*)playerID andMsgID:(NSInteger)msgID;
-(void) finishCatchingProcess:(NSTimer*) timer;
-(void) refree:(NSTimer*) timer;
-(void) bringHomeWithPlayerID:(NSString*)playerID andMsgID:(NSInteger)msgID;

//auxiliary methods
-(void) removePlayer:(Player*) player;

@end		
